const cloud = require("@cloudbase/node-sdk");

const app = cloud.init({
    env: cloud.SYMBOL_CURRENT_ENV,
});

var db = app.database();
const $ = db.command.aggregate
const _ = db.command
const nowDate = db.serverDate()

const AION_VER = db.collection('AION-VER')

// 获取openId云函数入口函数
exports.main = async (event, context) => {

    // return await AION_ZB_WQ.get()
    
    var type = event.data.type
    var form = event.data.form

    if(type=='addVER'){
        if(form._id){
            const res = await AION_VER.doc(form._id).update({
                content: form.content,
                title: form.title
            })
            return res.updated
        }else{
            if(form){
                form.createTime = nowDate
            }
            const res = await AION_VER.add(form)
            return {
                id: res.id
            };
        }
    }

    if(type=='getVER'){
        const res = await AION_VER.get()
        return res
    }


};
